package com.ruibang.glass.etl.handler.dcs;


import com.gitee.Jmysy.binlog4j.core.BinlogEvent;
import com.gitee.Jmysy.binlog4j.core.IBinlogEventHandler;
import com.gitee.Jmysy.binlog4j.springboot.starter.annotation.BinlogSubscriber;
import com.ruibang.glass.etl.entity.AlarmHistory;
import com.ruibang.glass.etl.entity.Dcstd02;
import com.ruibang.glass.etl.mapper.Dcstd02Mapper;
import com.ruibang.glass.etl.mapper.GlassAlarmHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;

@BinlogSubscriber(clientName = "dcs")
public class DCSTD02BinlogEventHandler implements IBinlogEventHandler<Dcstd02> {

    @Autowired
    private Dcstd02Mapper dcstd02Mapper;
    @Override
    public void onInsert(BinlogEvent<Dcstd02> event) {
        if(1 > dcstd02Mapper.insert(event.getData())){
            System.out.println("dcstd dcstd02 插入数据失败:" + event.getData());
        }else
            System.out.println("dcstd dcstd02 插入数据成功");
    }

    @Override
    public void onUpdate(BinlogEvent<Dcstd02> event)  {

            if(1 > dcstd02Mapper.updateById(event.getData())){
                String stringBuilder = event.getDatabase() + "-" +
                        event.getTable() + " update record fail,data: " + event.getData();
                System.out.println(stringBuilder);
            }else
                System.out.println("dcstd dcstd02 更新数据成功");

    }

    @Override
    public void onDelete(BinlogEvent<Dcstd02> event) {

        if(1 > dcstd02Mapper.deleteById(event.getData())){
            System.out.println("dcstd dcstd02 删除数据失败:" + event.getData());
        }else
            System.out.println("dcstd dcstd02 删除数据成功");
    }

    @Override
    public boolean isHandle(String database, String table) {
        return database.equals("dcstd") && table.equals("dcstd02");
    }
}
